package com.seaside.park.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.seaside.park.bean.cabinet.GoodInfo;
import com.seaside.park.mapper.cabinet.GoodInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class GoodService {

    @Autowired
    private GoodInfoMapper goodInfoMapper;

    public List<GoodInfo> getGoodListByType(int goodType){
        QueryWrapper<GoodInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("good_type",goodType).eq("if_publish",1);
        List<GoodInfo> temp = goodInfoMapper.selectList(queryWrapper);
        List<GoodInfo> ret = new ArrayList<>();
        List<String> imageList = new ArrayList<>();
        //处理图片
        for(GoodInfo goodInfo:temp){
            String[] images = goodInfo.getGoodImages().split(";");
            for(String image : images) {
                if(image!="") {
                    imageList.add(image);
                }
            }
            goodInfo.setGoodImageList(imageList);
            ret.add(goodInfo);
        }
        return ret;
    }
}